package model

import (
	"time"

	v1 "k8s.io/api/core/v1"
	"k8s.io/apimachinery/pkg/api/resource"
	"sigs.k8s.io/controller-runtime/pkg/cache"
	"sigs.k8s.io/controller-runtime/pkg/client"
)

// NetworkInfo is the network of vnode, will be set into node addresses
type NetworkInfo struct {
	NodeIP   string // IP address of the node
	HostName string // Hostname of the node
}

// NodeMetadata is the base data of a vnode, will be transfer to default labels of a vnode
type NodeMetadata struct {
	Name        string // Name of the vnode instance
	BaseName    string // BaseName of the base the vnode belongs to
	Version     string // Version of the vnode
	ClusterName string // ClusterName of the cluster the vnode belongs to
}

// NodeInfo is the data of node info.
type NodeInfo struct {
	Metadata          NodeMetadata      // Metadata of the node
	NetworkInfo       NetworkInfo       // Network information of the node
	CustomTaints      []v1.Taint        // Custom taints set by the tunnel
	CustomLabels      map[string]string // Custom labels set by the tunnel
	CustomAnnotations map[string]string // Custom annotations set by the tunnel
	State             NodeState         // Current state of the vnode
}

// NodeResource is the data of node resource
type NodeResource struct {
	Capacity    resource.Quantity // Capacity of the node
	Allocatable resource.Quantity // Allocatable resources of the node
}

// NodeStatusData is the status of a node, you can set some custom attributes in this data structure
type NodeStatusData struct {
	Resources        map[v1.ResourceName]NodeResource // Resources of the node
	CustomConditions []v1.NodeCondition               // Custom conditions set by the tunnel
}

// BizStatusData is the status data of a container
type BizStatusData struct {
	Key        string    // Key generated by tunnel, must be the same as Tunnel GetBizUniqueKey of same container
	Name       string    // Container name
	PodKey     string    // Key of pod which contains this container ,you can set it to PodKeyAll to present a shared container
	State      string    // State of the biz
	ChangeTime time.Time // Time of state change
	Reason     string    // Reason for state change
	Message    string    // Message for state change
}

type BuildVNodeConfig struct {
	Client            client.Client     // Runtime client instance
	KubeCache         cache.Cache       // Cache of kube resources
	BaseIP            string            // IP of the base
	BaseHostName      string            // Hostname of the base
	NodeIP            string            // NodeIP of the node
	NodeName          string            // NodeName of the node
	NodeVersion       string            // NodeVersion of the node
	BaseName          string            // BaseName of the base, which is the app name of base
	VPodType          string            // VPodType of the node
	ClusterName       string            // ClusterName of the node
	Env               string            // Environment of the node
	CustomTaints      []v1.Taint        // Custom taints set by the tunnel
	CustomLabels      map[string]string // Custom labels set by the tunnel
	CustomAnnotations map[string]string // Custom annotations set by the tunnel
	WorkerNum         int               // Worker num, if num is 1, means execute Container events serially
}

type BuildVNodeControllerConfig struct {
	KubeClient       client.Client // Runtime client instance
	KubeCache        cache.Cache   // Cache of kube resources
	ClientID         string        // Identity of vk instance, recommended to set it to pod name
	Env              string        // Environment of the vk instance
	VPodType         string        // VPod special value of model.LabelKeyOfComponent
	IsCluster        bool          // Whether the deployment is in a cluster
	WorkloadMaxLevel int           // Maximum workload level
	VNodeWorkerNum   int           // VNode container event processor worker num, default 1, means execute Container events serially
	PseudoNodeIP     string        // Pseudo node IP, will be used as the node IP for vnodes.
}

// QueryBaselineRequest is the request parameters of query baseline func
// Used to query baseline configuration with filters
type QueryBaselineRequest struct {
	Name         string            `json:"name"`         // Name to filter by
	Version      string            `json:"version"`      // Version to filter by
	CustomLabels map[string]string `json:"customLabels"` // Additional label filters
}
